INCLUDE(ExternalProject)

ExternalProject_Add(
    EasyCL-external
    SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/EasyCL
    PREFIX ${CMAKE_BINARY_DIR}/EasyCL
    STAMP_DIR ${CMAKE_BINARY_DIR}/EasyCL/stamp
    CMAKE_CACHE_ARGS 
    -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
    -DBUILD_SHARED_LIBRARY:BOOL=ON
    -DBUILD_TESTS:BOOL=OFF
	-DPROVIDE_LUA_ENGINE:BOOL=${BUILD_INTERNAL_LUA}
    -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo
    )

ADD_LIBRARY(EasyCL SHARED IMPORTED)
SET_PROPERTY(TARGET EasyCL PROPERTY IMPORTED_LOCATION "${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}EasyCL${CMAKE_SHARED_LIBRARY_SUFFIX}")
SET_PROPERTY(TARGET EasyCL PROPERTY IMPORTED_IMPLIB "${CMAKE_INSTALL_PREFIX}/lib/EasyCL.lib")
ADD_DEPENDENCIES(EasyCL EasyCL-external)
SET(EASYCL_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/EasyCL ${CMAKE_CURRENT_SOURCE_DIR}/EasyCL/thirdparty/clew/include  ${CMAKE_CURRENT_SOURCE_DIR}/EasyCL/thirdparty/clew/include/proxy-opencl)
#message("lib path ${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}EasyCL${CMAKE_SHARED_LIBRARY_SUFFIX}")
if(WIN32)
	SET(EASYCL_LIBRARIES ${CMAKE_INSTALL_PREFIX}/lib/EasyCL.lib ${CMAKE_INSTALL_PREFIX}/lib/clew.lib)
else()
	SET(EASYCL_LIBRARIES ${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}EasyCL${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}clew${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()
SET(EASYCL_FOUND ON)

add_custom_target(easycl_delete_stamp ALL 
  COMMAND ${CMAKE_COMMAND} -E  remove_directory "${CMAKE_BINARY_DIR}/EasyCL/stamp"
)
add_dependencies(EasyCL-external easycl_delete_stamp)

